<?php
class OrdersCyclesController extends AppController {

	var $name = 'OrdersCycles';
	
	var $permissions = array(
		'add' => array('admin','manag'),
		'index' => array('admin','manag'),
		'view' => array('admin','manag'),
		'edit' => array('admin','manag'),
		'delete' => array('admin','manag')
	);
	
	function index() {
		$this->OrdersCycle->recursive = 0;
		$this->set('ordersCycles', $this->paginate());
	}

	function view($id = null) {
		if (!$id) {
			$this->Session->setFlash(__("Invalid orders cycle", true));
			$this->redirect(array('action' => 'index'));
		}
		$this->set('ordersCycle', $this->OrdersCycle->read(null, $id));
	}

	function add() {
		if (!empty($this->data)) {
			$this->OrdersCycle->create();
			if ($this->OrdersCycle->save($this->data)) {
				$this->Session->setFlash(__("The orders cycle has been saved", true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__("The orders cycle could not be saved. Please, try again.", true));
			}
		}
		$orders = $this->OrdersCycle->Order->find('list');
		$this->set(compact('orders'));
	}

	function edit($id = null) {
		if (!$id && empty($this->data)) {
			$this->Session->setFlash(__("Invalid orders cycle", true));
			$this->redirect(array('action' => 'index'));
		}
		if (!empty($this->data)) {
			if ($this->OrdersCycle->save($this->data)) {
				$this->Session->setFlash(__("The orders cycle has been saved", true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__("The orders cycle could not be saved. Please, try again.", true));
			}
		}
		if (empty($this->data)) {
			$this->data = $this->OrdersCycle->read(null, $id);
		}
		$orders = $this->OrdersCycle->Order->find('list');
		$this->set(compact('orders'));
	}

	function delete($id = null) {
		if (!$id) {
			$this->Session->setFlash(__("Invalid id for orders cycle", true));
			$this->redirect(array('action'=>'index'));
		}
		if ($this->OrdersCycle->delete($id)) {
			$this->Session->setFlash(__("Orders cycle deleted", true));
			$this->redirect(array('action'=>'index'));
		}
		$this->Session->setFlash(__("Orders cycle was not deleted", true));
		$this->redirect(array('action' => 'index'));
	}

}
?>